package com.cskaoyan.weixin.service;

import com.cskaoyan.mapper.BrandMapper;
import com.cskaoyan.bean.Brand;
import com.cskaoyan.weixin.bean.brand.BrandListVO;
import com.cskaoyan.weixin.bean.home.BrandIndexVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandWxServiceImpl implements BrandWxService{

    @Autowired
    BrandMapper brandMapper;

    @Override
    public BrandListVO brandList(Integer page, Integer size) {
        PageHelper.startPage(page, size);

        List<BrandIndexVO> brandIndexVOS = brandMapper.queryAllBrandList();

        BrandListVO brandListVO = new BrandListVO();
        brandListVO.setBrandList(brandIndexVOS);

        PageInfo pageInfo = new PageInfo(brandIndexVOS);
        int pages = pageInfo.getPages();
        brandListVO.setTotalPages(pages);

        return brandListVO;
    }

    @Override
    public Brand brandDetail(Integer brandId) {
        Brand brand = brandMapper.selectBrandDetail(brandId);
        return brand;
    }
}
